export function pieOptions ({ data = [] }) :any {
  const newData:any = []
  let total = 0
  data.forEach((d, index) => {
    const { value, name } = d
    newData.push(
      Object.assign(
        { value, name },
        {
          label: {
            show: (function() {
              if (index === 0) {
                return true
              } else {
                return false
              }
            })(),
            padding: [0, -60],
            lineHeight: 30,
            formatter: '{c|{c}}\n{b|{b}}',
            rich: {
              c: {
                color: '#fff',
                fontSize: 22,
                fontWeight: 500,
                fontFamily: 'PingFang Regular'
              },
              b: {
                color: '#fff',
                fontSize: 14,
                fontWeight: 400,
                fontFamily: 'PingFang Regular'
              }
            },
            position: 'outside'
          },
          labelLine: {
            length: 25,
            length2: 80,
            // minAngle: 90,
            // minTurnAngle: 90,
            // maxSurfaceAngle: 90,
            show: (function() {
              if (index === 0) {
                return true
              } else {
                return false
              }
            })()
          },
          emphasis: {
            labelLine: {
              show: true
            }
          }
        }
      )
    )
    total += value
  })
  const color = 'rgba(255, 255, 255, 0)'
  const colorList = ['#21BAD6', '#25EFBD', '#E44660', '#E4A746', '#BD23F0', '#FFFFFF']
  return {
    color: colorList,
    backgroundColor: color,
    animation: true,
    title: {
      text: total,
      subtext: '总数',
      itemGap: 5,
      textStyle: {
        color: '#FFFFFF',
        fontSize: 28,
        fontWeight: 500,
        fontFamily: 'PingFang Regular'
      },
      subtextStyle: {
        fontSize: 18,
        color: ['#FFFFFF']
      },
      x: 'center',
      y: '42%'
    },
    tooltip: {
      show: true
    },
    legend: [
      {
        icon: 'roundRect',
        data: data.slice(0, 1),
        // width: '50%',
        bottom: '10%',
        left: '20%',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      },
      {
        icon: 'roundRect',
        data: data.slice(1, 2),
        // width: '50%',
        bottom: '10%',
        left: '42%',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        borderRadius: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      },
      {
        icon: 'roundRect',
        data: data.slice(2, 3),
        // width: '50%',
        bottom: '10%',
        left: '64%',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        borderRadius: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      },
      {
        icon: 'roundRect',
        data: data.slice(3, 4),
        // width: '50%',
        bottom: '3%',
        left: '20%',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        borderRadius: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      },
      {
        icon: 'roundRect',
        data: data.slice(4, 5),
        // width: '50%',
        bottom: '3%',
        left: '42%',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        borderRadius: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      },
      {
        icon: 'roundRect',
        data: data.slice(5, 6),
        // width: '50%',
        bottom: '3%',
        left: '64%',
        itemGap: 10,
        itemWidth: 16,
        itemHeight: 6,
        borderRadius: 6,
        textStyle: {
          color: '#ffffff',
          fontSize: 14,
          fontFamily: 'PingFang Regular'
        }
      }
    ],
    series: [
      {
        radius: ['50%', '57%'],
        center: ['50%', '50%'],
        type: 'pie',
        clockwise: true,
        // startAngle: -90,
        itemStyle: {
          normal: {
            borderWidth: 5,
            borderColor: '#0C192C'
          }
        },
        data: newData
      },
      {
        tooltip: {
          show: false
        },
        radius: ['43%', '50%'],
        center: ['50%', '50%'],
        type: 'pie',
        animation: false,
        hoverAnimation: false,
        labelLine: {
          show: false
        },
        data: [{
          value: 0,
          itemStyle: {
            color: '#0a3057'
          }
        }]
      },
      {
        tooltip: {
          show: false
        },
        radius: ['0', '32%'],
        center: ['50%', '50%'],
        type: 'pie',
        animation: false,
        hoverAnimation: false,
        labelLine: {
          show: false
        },
        data: [{
          value: 0,
          itemStyle: {
            color: '#0b345e'
          }
        }]
      }
    ]
  }
}
